package cn.com.cifi.mars.mapper.mars;

import java.time.LocalDateTime;
import java.util.List;

import org.apache.ibatis.annotations.Param;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import cn.com.cifi.mars.entity.ApprovalBill;

/**
 * 审批单
 * @author Administrator
 *
 */
public interface ApprovalBillMapper extends BaseMapper<ApprovalBill> {
	// 保存业务数据
	void saveBusinessData(ApprovalBill approvalBill);

	// 更新流程状态
	void updateApprovalState(@Param("key") String BusinessKey, @Param("state") String state,
			@Param("instId") String instId, @Param("taskId") String taskId, @Param("time") LocalDateTime dateTime);

	// 根据businessKey查询projectId
	String selectProjectIdByBusinessKey(@Param("key") String businessKey);

	// 查询审批说明
	String selectDescriptionByBusinessKey(@Param("key") String businessKey);

	// 根据businessKey查询实例ID
	ApprovalBill selectApprovalBillByKey(@Param("id") String businessKey);

	// 根据项目id查询项目的审批状态
	ApprovalBill selectStateByProjectId(@Param("projectId") String projectId);

	// 根据businessKey更新审批说明
	void updateDescByBusinessKey(@Param("key") String bussinesKey, @Param("description") String description,
			@Param("flowKey") String flowKey,@Param("account") String account,@Param("name") String name);

	// 根据projectId查询审批单
	List<ApprovalBill> selectRecordById(Page page, @Param("projectId") String projectId,
			@Param("searchStr") String searchStr, @Param("businessType") String businessType);

	ApprovalBill selectApprovalBillByProjectId(@Param("id") String projectId, @Param("state") String state ,@Param("bussinesType")String bussinesType);

	// 根据versionId查询审批单
	ApprovalBill selectBillByVersionId(@Param("versionId") String versionId);

	//根据类型和项目id和状态查询审批单
	String selectByProjectIdAndTypeAndState(@Param("projectId") String projectId, @Param("businessType") String businessType
			,@Param("state") String state);

	//获取上一次审批单
    ApprovalBill getLastApprovalBill(ApprovalBill approvalBill);

	/**
	 * 获取项目、审批单类型下（审批单状态不是删除和废弃）最新的审批单
	 * @param businessType
	 * @param projectId
	 * @return
	 */
	ApprovalBill getNewApprovalBill(@Param("businessType") String businessType,@Param("projectId") String projectId,
									@Param("yearMonth") String yearMonth);

	ApprovalBill selectNewestByProjectId(@Param("projectId") String projectId, @Param("state") String state, @Param("businessType") String businessType);
}
